//请求用
var DBtable_config_request = {};
//请求用
var proto_field_request = {};
//表格用
var tablelist = []
//穿越用
var protofeild = []
//穿越用
var protolist = []
//穿越用
var editmodel = []

var storage_rule_select = []

var showtablelist = []

var field

var transferIdGroup = []

var segment_modify_id = 0;
var segment_modify_protoName
var proto_field_modify = []
var proto_field_modify_idArr
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

$.ajax({
	url: 'http://' + ipm + ':8081/dict/query',
	type: 'POST',
	contentType: 'application/json',
	dataType: 'json',
	data: {},
	success: function (response) {
		DBtableConfigRead(response)
		createProtofieldobj(response);
		createProtoObj(response)
		// createTransfer();
		bootstrapTable_init();
		//下拉菜单赋值
		layui.use(['form', 'upload', 'layer', 'table'], function () {
			var form = layui.form;
			//使用循环遍历，给下拉列表赋值
			$.each(protolist, function (index, value) {
				$('#dp').append(new Option(value.name, value.name + ":" + value.segment_list));// 下拉菜单里添加元素
			});
			$.each(storage_rule_select, function (index, value) {
				$('#storage_rule').append(new Option(value.name, JSON.stringify(value)));// 下拉菜单里添加元素
			});
			console.log(protolist);
			console.log(protofeild);


			$(document).ready(function () {
				// select下拉框选中触发事件
				form.on('select(xmFilter)', function (data) {
					console.log(data.value);
					var index1 = data.value.indexOf(':')
					// var index2 = data.value.indexOf(';')
					var dataA = data.value.substring(index1 + 1)
					// console.log(dataA);

					var idArr = dataA.split(",")
					console.log(idArr);
					var pfrArr = proto_field_request.protocol_segments
					console.log(pfrArr);
					showtablelist = []
					var k = 1
					for (var i = 0; i < idArr.length; i++) {
						for (var j = 0; j < pfrArr.length; j++) {
							if (pfrArr[j].id == parseInt(idArr[i])) {
								var showObj = {
									"id": "",
									"name": "",
									"dbfield": "",
									"value_type": "",
									"value_length": "",
									"method": "",
									"value": "",
									"ID": ""
								}
								showObj.id = pfrArr[j].id;
								showObj.name = pfrArr[j].name;
								showObj.dbfield = pfrArr[j].dbfield;
								showObj.value_type = pfrArr[j].value_type;
								showObj.value_length = pfrArr[j].value_length;
								if (pfrArr[j].dict_name) {
									showObj.method = "dict_name";
									showObj.value = pfrArr[j].dict_name;
								}
								else if (pfrArr[j].logical_expressions) {
									showObj.method = "logical_expressions";
									showObj.value = pfrArr[j].logical_expressions;
								}
								else if (pfrArr[j].parse_list_name) {
									showObj.method = "parse_list_name";
									showObj.value = pfrArr[j].parse_list_name;
								}
								else if (pfrArr[j].string) {
									showObj.method = "string";
									showObj.value = pfrArr[j].string;
								}
								else if (pfrArr[j].strtrim) {
									showObj.method = "strtrim";
									showObj.value = pfrArr[j].strtrim;
								}
								showObj.ID = k++;

								showtablelist.push(showObj)
							}
						}
					}
					console.log(showtablelist);
					createTransfer1(showtablelist);


				});
			});

			form.render("select");
		});
	}
});

//穿越框配置
function createTransfer1(showtablelist) {
	var segment_transfer = []
	for (var i = 0; i < showtablelist.length; i++) {
		var obj = {
			"value": ""
			, "title": ""
		}
		var method
		if (showtablelist[i].method == "dict_name") {
			method = "字典";
		} else if (showtablelist[i].method == "logical_expressions") {
			method = "逻辑表达式";
		} else if (showtablelist[i].method == "parse_list_name") {
			method = "解析表";
		} else if (showtablelist[i].method == "string" && showtablelist[i].value == "ascii") {
			method = "字符串";
		} else if (showtablelist[i].method == "string" && showtablelist[i].value == "hex") {
			method = "原始值";
		} else if (showtablelist[i].method == "strtrim") {
			method = "分隔符";
		}
		var segment_title = showtablelist[i].ID + "|" + showtablelist[i].name + "|" + showtablelist[i].dbfield + "|" + showtablelist[i].value_type + "|" + showtablelist[i].value_length + "|" + method + "|" + showtablelist[i].value;
		obj.value = showtablelist[i].id;
		obj.title = segment_title;
		segment_transfer.push(obj);
	}
	console.log(segment_transfer);
	layui.use(['transfer', 'layer', 'util'], function () {
		var $ = layui.$
			, transfer = layui.transfer
			, layer = layui.layer
			, util = layui.util;
		//基础效果
		transfer.render({
			elem: '#test1'
			, data: segment_transfer
			, id: 'key123'
			, title: ['待选字段', '已选字段']
			, showSearch: true
			, width: 300 //定义宽度
			, height: 330 //定义高度
		})
		//批量办法定事件
		util.event('lay-demoTransferActive', {
			getData: function (othis) {
				transferIdGroup = []
				var getData = transfer.getData('key123'); //获取右侧数据
				//layer.alert(JSON.stringify(getData));
				for (var i = 0; i < getData.length; i++) {
					transferIdGroup.push(getData[i].value);
				}
				console.log(transferIdGroup);
			}
		});
	});
}


function bootstrapTable_init() {
	$("#bootstrap-table").bootstrapTable('destroy').bootstrapTable({
		data: tablelist,
		dataType: 'json',
		pagination: true,                   //是否显示分页（*）
		cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		sortOrder: "asc",                   //排序方式
		sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
		pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
		pageSize: 10,                     //每页的记录行数（*）
		pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
		strictSearch: true,
		minimumCountColumns: 1,             //最少允许的列数
		uniqueId: "id",                     //每一行的唯一标识，一般为主键列
		onEditableSave: onEditableSave,
		columns: [
			[{
				title: '基础信息',
				align: 'center',
				colspan: 3
			}, {
				title: '表空间最大容量',
				align: 'center',
				colspan: 2
			}, {
				title: '其他信息',
				align: 'center',
				colspan: 2
			}
			],
			[
				{
					field: 'ID',
					align: 'center',
					title: '序号',
					width: 60,
					formatter: function (value, row, index) {
						return index + 1;
					}
				}, {
					field: 'tlbname',
					align: 'center',
					title: '数据库表名称',
					width: 160,
					editable: editable_cn
				}, {
					field: 'segments',
					align: 'center',
					title: '表字段',
					width: 60,
					formatter: function (value, row, index) {
						var result = "";
						result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"arr_Dbtbl_modify('" + index + "','" + value + "')\" title='编辑'><span class='feather-edit'></span></a>";
						return result;
					}
				}, {
					field: 'maxsize_val',
					align: 'center',
					title: '大小',
					width: 80,
					editable: sizeLimit
				}, {
					field: 'maxsize_unit',
					align: 'center',
					title: '单位',
					width: 80,
					editable: {
						type: 'select',
						title: '值类型',
						source: [{
							value: "TB",
							text: "TB"
						}, {
							value: "GB",
							text: "GB"
						}
						]
					}
				}, {
					field: 'comment',
					align: 'center',
					title: '备注',
					editable: editable_cn
				}, {
					field: 'id',
					align: 'center',
					title: '删除',
					width: 60,
					formatter: function (value, row, index) {
						var id = value;
						var result = "";
						result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"arr_Dbtbl_delete(" + id + ")\" title='删除'><span class='feather-trash-2'></span></a>";
						return result;
					}
				}
			]]
	});
}

//大小输入限制
function sizeLimit(rowIndex) {
	// console.log(rowIndex)
	var data = $("#bootstrap-table").bootstrapTable('getData');
	// console.log(data[rowIndex])
	// console.log(data[rowIndex].maxsize_unit)

	if (data[rowIndex].maxsize_unit == "TB") {
		return {
			disabled: true
		}
	} else if (data[rowIndex].maxsize_unit == "GB") {
		return {
			type: 'number',
			min: 0,
			max: 1023
		}
	}
}
//表内修改配置函数
function onEditableSave(field, row, rowIndex, oldValue, $el) {
	// alert("字段名：" + field + "，当前值：" + row[field] + "，旧值：" + oldValue + "，顺位：" + rowIndex);
	var data = $("#bootstrap-table").bootstrapTable('getData');
	var objChange = data[rowIndex];
	var idChange = objChange.id;
	var arr = DBtable_config_request.tables;
	var DbtblWeb = {
		"cfgType": "9",
		"cfgName": "database_tbl_cfg.json",
		"content": ""
	}
	var DbtblSave = {
		"cfg_type": 9,
		"max_id": "",
		"tables": ""
	}
	if (field == "tlbname") {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].id == idChange) {
				arr[i].tlbname = row[field];
			}
		}

	}
	// else if (field == "segments") {
	// 	//穿越
	// 	for (var i = 0; i < arr.length; i++) {
	// 		if (arr[i].id == idChange) {
	// 			arr[i].segments = parseInt(row[field]);
	// 		}
	// 	}
	// 	DbtblSave.tables = arr;
	// 	DbtblSave.max_id = DBtable_config_request.max_id;
	// 	DbtblWeb.content = JSON.stringify(DbtblSave)
	// 	postQuestSave(DbtblWeb);
	// 	layer.msg('修改成功', { icon: 1 });
	// } 
	else if (field == "maxsize_val") {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].id == idChange) {
				arr[i].maxsize.val = parseInt(row[field]);
			}
		}

	} else if (field == "maxsize_unit") {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].id == idChange) {
				if (row[field] == "TB") {
					arr[i].maxsize.val = 1;
					arr[i].maxsize.unit = row[field];
				} else if (row[field] == "GB") {
					arr[i].maxsize.unit = row[field];
				}
			}
		}

	} else if (field == "comment") {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].id == idChange) {
				arr[i].comment = row[field];
			}
		}
	}
	DbtblSave.tables = arr;
	DbtblSave.max_id = DBtable_config_request.max_id;
	DbtblWeb.content = JSON.stringify(DbtblSave)
	// postQuestSave(DbtblWeb);
	////////////////////////////////////////////////
	////////////////请求发送并重新建表///////////////
	////////////////////////////////////////////////
	var xhr = new XMLHttpRequest();
	// 配置请求
	xhr.open('POST', 'http://' + ipm + ':8081/dict/save', true);
	xhr.setRequestHeader('content-Type', 'application/json');
	// 发送 JSON 数据
	xhr.send(JSON.stringify(DbtblWeb));
	// 监听请求的状态
	xhr.onreadystatechange = function () {
		console.log(xhr.readyState);
		if (xhr.readyState === 4 && xhr.status === 200) {
			console.log(xhr.responseText);
			$.ajax({
				url: 'http://' + ipm + ':8081/dict/query',
				type: 'POST',
				contentType: 'application/json',
				dataType: 'json',
				data: {},
				success: function (response) {
					tablelist = []
					console.log(response);
					DBtableConfigRead(response)
					bootstrapTable_init()
				}
			});
		}
	};
	layer.msg('修改成功', { icon: 1 });
}

//穿梭框顺序调整
function transferRightSort(arr) {
	for (var i = 0; i < arr.length; i++) {
		arr[i] = parseInt(arr[i])
	}
	// console.log(arr)
	var data = $("ul.layui-transfer-data")[1]
	// console.log(data)
	var item_list = $(data).children("li")
	var middle_list = []
	for (var key in arr) {
		middle_list.push("")
	}
	for (var i = 0; i < item_list.length; i++) {
		var item = item_list[i]
		// console.info(item);
		var value = $(item_list).children("input")[i].value
		// console.info(value);
		var index = arr.indexOf(parseInt(value))
		// console.info(index);
		middle_list[index] = item
	}
	var innertHTML = ""
	for (var y = 0; y < middle_list.length; y++) {
		console.info($(middle_list).children("input")[y].value)
		// console.info(middle_list[i].HTML)
		innertHTML += "<li>" + middle_list[y].innerHTML + "</li>"
	}
	$($("ul.layui-transfer-data")[1]).html(innertHTML)
	// console.info(innertHTML)
}



//表字段修改
function arr_Dbtbl_modify(rowIndex, value) {
	console.log(rowIndex)
	console.log(value)
	segment_modify_id = DBtable_config_request.tables[rowIndex].id
	console.log(segment_modify_id)
	segment_modify_protoName = DBtable_config_request.tables[rowIndex].protoname
	console.log(segment_modify_protoName)
	var segment_transfer_modify = []
	var segment_selected = value.split(",")
	var proto_file_arr = proto_field_request.protocol_segments
	console.log(proto_file_arr)


	console.log(protolist)
	for (var i = 0; i < protolist.length; i++) {
		if (protolist[i].name == segment_modify_protoName) {
			proto_field_modify_idArr = protolist[i].segment_list
		}
	}
	console.log(proto_field_modify_idArr)

	proto_field_modify = []
	var k = 1
	for (var i = 0; i < proto_file_arr.length; i++) {
		for (var j = 0; j < proto_field_modify_idArr.length; j++) {
			if (proto_file_arr[i].id == proto_field_modify_idArr[j]) {
				// proto_field_modify.push(proto_file_arr[i])
				var showObj = {
					"id": "",
					"name": "",
					"dbfield": "",
					"value_type": "",
					"value_length": "",
					"method": "",
					"value": "",
					"ID": ""
				}
				showObj.id = proto_file_arr[i].id;
				showObj.name = proto_file_arr[i].name;
				showObj.dbfield = proto_file_arr[i].dbfield;
				showObj.value_type = proto_file_arr[i].value_type;
				showObj.value_length = proto_file_arr[i].value_length;
				if (proto_file_arr[i].dict_name) {
					showObj.method = "dict_name";
					showObj.value = proto_file_arr[i].dict_name;
				}
				else if (proto_file_arr[i].logical_expressions) {
					showObj.method = "logical_expressions";
					showObj.value = proto_file_arr[i].logical_expressions;
				}
				else if (proto_file_arr[i].parse_list_name) {
					showObj.method = "parse_list_name";
					showObj.value = proto_file_arr[i].parse_list_name;
				}
				else if (proto_file_arr[i].string) {
					showObj.method = "string";
					showObj.value = proto_file_arr[i].string;
				}
				else if (proto_file_arr[i].strtrim) {
					showObj.method = "strtrim";
					showObj.value = proto_file_arr[i].strtrim;
				}
				showObj.ID = k++;

				proto_field_modify.push(showObj)
			}
		}
	}

	console.log(proto_field_modify)

	for (var i = 0; i < proto_field_modify.length; i++) {
		var obj = {
			"value": ""
			, "title": ""
		}
		var method
		if (proto_field_modify[i].method == "dict_name") {
			method = "字典";
		} else if (proto_field_modify[i].method == "logical_expressions") {
			method = "逻辑表达式";
		} else if (proto_field_modify[i].method == "parse_list_name") {
			method = "解析表";
		} else if (proto_field_modify[i].method == "string" && proto_field_modify[i].value == "ascii") {
			method = "字符串";
		} else if (proto_field_modify[i].method == "string" && proto_field_modify[i].value == "hex") {
			method = "原始值";
		} else if (proto_field_modify[i].method == "strtrim") {
			method = "分隔符";
		}
		var segment_title = proto_field_modify[i].ID + "|" + proto_field_modify[i].name + "|" + proto_field_modify[i].dbfield + "|" + proto_field_modify[i].value_type + "|" + proto_field_modify[i].value_length + "|" + method + "|" + proto_field_modify[i].value;
		obj.value = proto_field_modify[i].id;
		obj.title = segment_title;
		segment_transfer_modify.push(obj);
	}
	layui.use(['transfer', 'layer', 'util'], function () {
		var $ = layui.jquery
		var $ = layui.$
			, transfer = layui.transfer
			, layer = layui.layer
			, util = layui.util;

		var selectedTransfers = []
		//基础效果
		transfer.render({
			elem: '#test2'
			, data: segment_transfer_modify
			, id: 'key123'
			, title: ['待选字段', '已选字段']
			, value: segment_selected
			, showSearch: true
			, width: 300 //定义宽度
			, height: 350 //定义高度
		})
		transferRightSort(segment_selected)


		//批量办法定事件
		util.event('lay-demoTransferActive', {
			getData_modify: function (othis) {
				transferIdGroup = []
				var getData = transfer.getData('key123'); //获取右侧数据
				//layer.alert(JSON.stringify(getData));
				for (var i = 0; i < getData.length; i++) {
					transferIdGroup.push(getData[i].value);
				}
				console.log(transferIdGroup);
				var arrDbtbl = DBtable_config_request.tables;
				var DbtblWeb = {
					"cfgType": "9",
					"cfgName": "database_tbl_cfg.json",
					"content": ""
				}
				var DbtblSave = {
					"cfg_type": 9,
					"max_id": "",
					"tables": ""
				}
				for (var i = 0; i < arrDbtbl.length; i++) {
					if (arrDbtbl[i].id == segment_modify_id) {
						arrDbtbl[i].segments = transferIdGroup
					}
				}
				// arrDbtbl[segment_modify_id].segments = transferIdGroup
				DbtblSave.tables = arrDbtbl;
				DbtblSave.max_id = DBtable_config_request.max_id;
				DbtblWeb.content = JSON.stringify(DbtblSave);
				console.log(DbtblSave);
				postQuestSave(DbtblWeb);
				alert("新增成功！");
			}
		});
	});
	$('#segementModal').modal('show');
}


// //表字段修改
// function arr_Dbtbl_modify(rowIndex, value) {
// 	console.log(rowIndex)
// 	console.log(value)
// 	segment_modify_id = DBtable_config_request.tables[rowIndex].id
// 	console.log(segment_modify_id)
// 	var segment_transfer_modify = []
// 	var segment_selected = value.split(",")
// 	for (var i = 0; i < protofeild.length; i++) {
// 		var obj = {
// 			"value": ""
// 			, "title": ""
// 		}
// 		var method
// 		if (protofeild[i].method == "dict_name") {
// 			method = "字典";
// 		} else if (protofeild[i].method == "logical_expressions") {
// 			method = "逻辑表达式";
// 		} else if (protofeild[i].method == "parse_list_name") {
// 			method = "解析表";
// 		} else if (protofeild[i].method == "string" && protofeild[i].value == "ascii") {
// 			method = "字符串";
// 		} else if (protofeild[i].method == "string" && protofeild[i].value == "hex") {
// 			method = "原始值";
// 		} else if (protofeild[i].method == "strtrim") {
// 			method = "分隔符";
// 		}
// 		var segment_title = protofeild[i].ID + "|" + protofeild[i].name + "|" + protofeild[i].dbfield + "|" + protofeild[i].value_type + "|" + protofeild[i].value_length + "|" + method + "|" + protofeild[i].value;
// 		obj.value = protofeild[i].id;
// 		obj.title = segment_title;
// 		segment_transfer_modify.push(obj);
// 	}
// 	layui.use(['transfer', 'layer', 'util'], function () {
// 		var $ = layui.$
// 			, transfer = layui.transfer
// 			, layer = layui.layer
// 			, util = layui.util;
// 		//基础效果
// 		transfer.render({
// 			elem: '#test2'
// 			, data: segment_transfer_modify
// 			, id: 'key123'
// 			, title: ['待选字段', '已选字段']
// 			, value: segment_selected
// 			, showSearch: true
// 			, width: 300 //定义宽度
// 			, height: 350 //定义高度
// 		})
// 		//批量办法定事件
// 		util.event('lay-demoTransferActive', {
// 			getData_modify: function (othis) {
// 				transferIdGroup = []
// 				var getData = transfer.getData('key123'); //获取右侧数据
// 				//layer.alert(JSON.stringify(getData));
// 				for (var i = 0; i < getData.length; i++) {
// 					transferIdGroup.push(getData[i].value);
// 				}
// 				console.log(transferIdGroup);
// 				var arrDbtbl = DBtable_config_request.tables;
// 				var DbtblWeb = {
// 					"cfgType": "9",
// 					"cfgName": "database_tbl_cfg.json",
// 					"content": ""
// 				}
// 				var DbtblSave = {
// 					"cfg_type": 9,
// 					"max_id": "",
// 					"tables": ""
// 				}
// 				for (var i = 0; i < arrDbtbl.length; i++) {
// 					if (arrDbtbl[i].id == segment_modify_id) {
// 						arrDbtbl[i].segments = transferIdGroup
// 					}
// 				}
// 				// arrDbtbl[segment_modify_id].segments = transferIdGroup
// 				DbtblSave.tables = arrDbtbl;
// 				DbtblSave.max_id = DBtable_config_request.max_id;
// 				DbtblWeb.content = JSON.stringify(DbtblSave);
// 				console.log(DbtblSave);
// 				postQuestSave(DbtblWeb);
// 				alert("新增成功！");
// 			}
// 		});
// 	});
// 	$('#segementModal').modal('show');
// }


//新增数据库表配置
function createDBtableModel() {
	$('#DBtableModal').modal('show');

}




layui.use('form', function () {
	var form = layui.form;


	//TB/GB选择框
	form.on('select(maxsize_unit)', function (data) {
		// console.log(data.value); 
		if (data.value == "TB") {
			document.getElementById("maxsize_val").value = 1
			document.getElementById("maxsize_val").disabled = true
		} else {
			document.getElementById("maxsize_val").value = ""
			document.getElementById("maxsize_val").disabled = false
		}
		form.render()

	});
	//方法提交
	$('#testSubmitBtn').on('click', function (data) {
		form.submit('DBtable', function (data) { // 注：v2.7.0 新增
			// 回调函数返回结果跟上述 submit 事件完全一致
			document.getElementById("maxsize_val").disabled = false
			field = data.field;
			console.log(data.field)
			// do something
			buildDbtblJson();
			document.getElementById("maxsize_val").disabled = true
		});
		return false;
	});

});

layui.config({
	base: 'step-lay/'
}).use(['form', 'step'], function () {
	var $ = layui.$
		, form = layui.form
		, step = layui.step;

	step.render({
		elem: '#stepForm',
		filter: 'stepForm',
		width: '100%', //设置容器宽度
		stepWidth: '750px',
		height: '500px',
		stepItems: [{
			title: '第一步'
		}, {
			title: '第二步'
		}, {
			title: '完成'
		}]
	});


	form.on('submit(formStep)', function (data) {
		step.next('#stepForm');
		return false;
	});

	form.on('submit(formStep2)', function (data) {
		step.next('#stepForm');
		return false;
	});

	$('.pre').click(function () {
		step.pre('#stepForm');
	});

	$('.next').click(function () {
		step.next('#stepForm');
	});
})

//穿越框配置
function createTransfer() {
	var segment_transfer = []
	for (var i = 0; i < protofeild.length; i++) {
		var obj = {
			"value": ""
			, "title": ""
		}
		var method
		if (protofeild[i].method == "dict_name") {
			method = "字典";
		} else if (protofeild[i].method == "logical_expressions") {
			method = "逻辑表达式";
		} else if (protofeild[i].method == "parse_list_name") {
			method = "解析表";
		} else if (protofeild[i].method == "string" && protofeild[i].value == "ascii") {
			method = "字符串";
		} else if (protofeild[i].method == "string" && protofeild[i].value == "hex") {
			method = "原始值";
		} else if (protofeild[i].method == "strtrim") {
			method = "分隔符";
		}
		var segment_title = protofeild[i].ID + "|" + protofeild[i].name + "|" + protofeild[i].dbfield + "|" + protofeild[i].value_type + "|" + protofeild[i].value_length + "|" + method + "|" + protofeild[i].value;
		obj.value = protofeild[i].id;
		obj.title = segment_title;
		segment_transfer.push(obj);
	}
	console.log(segment_transfer);
	layui.use(['transfer', 'layer', 'util'], function () {
		var $ = layui.$
			, transfer = layui.transfer
			, layer = layui.layer
			, util = layui.util;
		//基础效果
		transfer.render({
			elem: '#test1'
			, data: segment_transfer
			, id: 'key123'
			, title: ['待选字段', '已选字段']
			, showSearch: true
			, width: 300 //定义宽度
			, height: 330 //定义高度
		})
		//批量办法定事件
		util.event('lay-demoTransferActive', {
			getData: function (othis) {
				transferIdGroup = []
				var getData = transfer.getData('key123'); //获取右侧数据
				//layer.alert(JSON.stringify(getData));
				for (var i = 0; i < getData.length; i++) {
					transferIdGroup.push(getData[i].value);
				}
				console.log(transferIdGroup);
			}
		});
	});
}

//增加/加入一个数据库表配置JSON
function buildDbtblJson() {
	var arrDbtbl = DBtable_config_request.tables;
	var id = DBtable_config_request.max_id;
	id++;
	var DbtblWeb = {
		"cfgType": "9",
		"cfgName": "database_tbl_cfg.json",
		"content": ""
	}
	var DbtblSave = {
		"cfg_type": 9,
		"max_id": "",
		"tables": ""
	}
	if (id) {
		Dbtbls = {
			"id": "",
			"tlbname": "", // database table name，数据库表的名称
			"protoname": "",
			"segments": "", // 一组协议字段的id, 获取协议字段的dbfield生成表
			"maxsize": "", //表的最大空间容量
			"comment": "", // 备注信息
			"isactive": false // 表是否已被使用，true - 已被使用，不能被修改； false - 未被使用，可以修改
		}
		Dbtbls.id = id;
	} else {
		arrDbtbl = []
		Dbtbls = {
			"id": "",
			"tlbname": "", // database table name，数据库表的名称
			"protoname": "",
			"segments": "", // 一组协议字段的id, 获取协议字段的dbfield生成表
			"maxsize": "", //表的最大空间容量
			"comment": "", // 备注信息
			"isactive": false // 表是否已被使用，true - 已被使用，不能被修改； false - 未被使用，可以修改
		}
		id = 0;
		Dbtbls.id = 0;
	}
	Dbtbls.tlbname = field.dbfield
	var index = field.dp.indexOf(':')
	var dp_protoname = field.dp.substring(0, index)
	Dbtbls.protoname = dp_protoname
	console.log(dp_protoname)
	Dbtbls.segments = transferIdGroup
	var maxsizeObj = {
		"val": "",
		"unit": ""
	}
	maxsizeObj.val = parseInt(field.maxsize_val)
	maxsizeObj.unit = field.maxsize_unit
	Dbtbls.maxsize = maxsizeObj
	Dbtbls.comment = field.comment
	arrDbtbl.push(Dbtbls);
	DbtblSave.tables = arrDbtbl;
	DbtblSave.max_id = id;
	DbtblWeb.content = JSON.stringify(DbtblSave);
	console.log(DbtblSave);
	postQuestSave(DbtblWeb);
	alert("新增成功！");
	//refreshTab();
	window.location.reload();

}



//删除数据库表配置JSON
function arr_Dbtbl_delete(args) {

	console.log(args)
	var arrDbtbl = DBtable_config_request.tables;
	for (var i = 0; i < arrDbtbl.length; i++) {
		if (arrDbtbl[i].id == args) {
			arrDbtbl.splice(i, 1);
			console.log(arrDbtbl)

		}
	}
	var DbtblWeb = {
		"cfgType": "9",
		"cfgName": "database_tbl_cfg.json",
		"content": ""
	}
	var DbtblSave = {
		"cfg_type": 9,
		"max_id": "",
		"tables": ""
	}
	DbtblSave.tables = arrDbtbl;
	DbtblSave.max_id = DBtable_config_request.max_id;
	DbtblWeb.content = JSON.stringify(DbtblSave);
	console.log(DbtblSave);
	postQuestSave(DbtblWeb);
	window.location.reload();
}